<template>
  <a-card class="j-inner-table-wrapper" :bordered="false">

    <!-- 查询区域 begin -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :xl="9" :lg="10" :md="11" :sm="27">
            <a-form-item label="验证时间">
              <a-range-picker
                :show-time="{
                format: 'HH:mm:ss',
                defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')]}"
                :format="dateFormat"
                :placeholder="['请选择开始日期', '请选择结束日期']"
                :default-value="[moment(date_begin, dateFormat), moment(date_end, dateFormat)]"
                @change="onChange"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="5" :md="6" :sm="22">
            <a-form-item label="状态">
              <j-dict-select-tag v-model="queryParam.isAvailable" placeholder="请选择状态" dictCode="is_available"/>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="6" :md="7" :sm="23">
            <a-form-item label="旺旺账号">
              <a-input v-model="queryParam.wangwang" placeholder="请输入旺旺账号"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="实名状态">
                <j-dict-select-tag v-model="queryParam.realNameStatus" placeholder="请选择实名状态" dictCode="real_name_status"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="账号类型">
            <j-dict-select-tag v-model="queryParam.sellerTotalNum" placeholder="请选择账号类型" dictCode="seller_total_num"/>
          </a-form-item>
        </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span class="table-page-search-submitButtons table-operator">
              <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" icon="reload" @click="searchReset">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                <span>{{ toggleSearchStatus ? '收起' : '展开' }}</span>
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域 end -->

    <!-- 操作按钮区域 begin -->
    <div class="table-operator">
      <a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('验号基本信息')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-button type="primary" @click="getAllTXMWWRateInfo">照一下</a-button>

      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            <span>删除</span>
          </a-menu-item>
        </a-menu>
        <a-button>
          <span>批量操作</span>
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>
    <!-- 操作按钮区域 end -->

    <!-- table区域 begin -->
    <div>

      <a-alert type="info" showIcon style="margin-bottom: 16px;">
        <template slot="message">
          <span>已选择</span>
          <a style="font-weight: 600;padding: 0 4px;">{{ selectedRowKeys.length }}</a>
          <span>项</span>
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </template>
      </a-alert>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :loading="loading"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :expandedRowKeys="expandedRowKeys"
        :rowSelection="{selectedRowKeys, onChange: onSelectChange}"
        @expand="handleExpand"
        @change="handleTableChange"
      >

        <!-- 内嵌table区域 begin -->
        <template slot="expandedRowRender" slot-scope="record">
          <a-tabs tabPosition="top">
            <a-tab-pane tab="评价" key="evaluate" forceRender>
              <evaluate-sub-table :record="record"/>
            </a-tab-pane>
          </a-tabs>
        </template>
        <!-- 内嵌table区域 end -->

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>

        <template slot="imgSlot" slot-scope="text">
          <div style="font-size: 12px;font-style: italic;">
            <span v-if="!text">无图片</span>
            <img v-else :src="getImgView(text)" alt="" style="max-width:80px;height:25px;"/>
          </div>
        </template>

        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            ghost
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)"
          >
            <span>下载</span>
          </a-button>
        </template>

        <template slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">
              <span>更多 <a-icon type="down"/></span>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>

        </template>

      </a-table>
    </div>
    <!-- table区域 end -->

    <!-- 表单区域 -->
    <yh-basic-modal ref="modalForm" @ok="modalFormOk"/>

  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import YhBasicModal from './modules/YhBasicModal'
  import EvaluateSubTable from './subTables/EvaluateSubTable'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import JDate from '@/components/jeecg/JDate.vue'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import '@/assets/less/TableExpand.less'
  import { postAction } from "@/api/manage";
  import moment from 'moment';

  export default {
    name: 'YhBasicList',
    mixins: [JeecgListMixin],
    components: {
      YhBasicModal,
      EvaluateSubTable,
      JDate,
      JDictSelectTag,
    },
    data() {
      return {
        description: '验号基本信息列表管理页面',
        queryParam: {
          finishtsStr_begin: null,
          finishtsStr_end: null
        },
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        date_begin: moment().subtract(7, "days").format("YYYY-MM-DD 00:00:00"),
        date_end: moment().format("YYYY-MM-DD 23:59:59"),
        // 表头
        columns: [
          {
            title: '#',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: (t, r, index) => parseInt(index) + 1
          },
          {
            title: '旺旺账号',
            align: 'center',
            dataIndex: 'wangwang',
          },
          {
            title: '状态',
            align: 'center',
            dataIndex: 'isAvailable_dictText',
          },
          {
            title: '买家信用',
            align: 'center',
            dataIndex: 'buyerScore',
          },
          {
            title: '周均信用点数',
            align: 'center',
            dataIndex: 'weekCreditAverage',
          },
          {
            title: '实名状态',
            align: 'center',
            dataIndex: 'realNameStatus_dictText'
          },
          {
            title: '账号类型',
            align: 'center',
            dataIndex: 'sellerTotalNum_dictText'
          },
          {
            title: '降权处置',
            align: 'center',
            dataIndex: 'msg',
          },
          {
            title: '开始时间',
            align: 'center',
            dataIndex: 'createtsStr',
          },
          {
            title: '结束时间',
            align: 'center',
            dataIndex: 'finishtsStr',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' },
          },
        ],
        // 字典选项
        dictOptions: {},
        // 展开的行test
        expandedRowKeys: [],
        url: {
          list: '/yanhao/yhBasic/list',
          delete: '/yanhao/yhBasic/delete',
          deleteBatch: '/yanhao/yhBasic/deleteBatch',
          exportXlsUrl: '/yanhao/yhBasic/exportXls',
          importExcelUrl: '/yanhao/yhBasic/importExcel',
        },
      }
    },
    computed: {
      importExcelUrl() {
        return window._CONFIG['domianURL'] + this.url.importExcelUrl
      }
    },
    methods: {
      moment,
      initDictConfig() {
      },

      handleExpand(expanded, record) {
        this.expandedRowKeys = []
        if (expanded === true) {
          this.expandedRowKeys.push(record.id)
        }
      },
      onChange(value, dateString) {
        this.queryParam.finishtsStr_begin = dateString[0]
        this.queryParam.finishtsStr_end = dateString[1]
      },
      getAllTXMWWRateInfo() {
        if (this.queryParam.finishtsStr_begin == null) {
          this.$message.warning('请选择开始时间！');
          return;
        }
        if (this.queryParam.finishtsStr_end == null) {
          this.$message.warning('请选择结束时间！');
          return;
        }
        postAction("/yanhao/yhBasic/getRateInfo", this.queryParam).then(res => {
          if (res.success) {
            this.searchQuery()
          }
        })
      }
    }
  }
</script>
<style lang="less" scoped>
  @import '~@assets/less/common.less';
</style>